#include <iostream>
#include <string>


struct Result {
	bool is2;
	bool is8;
	bool is10;
	bool is16;	
};

inline Result Check(std::string& num) {
	Result result = { false, false, false, false };

	char largest = num[0];
	for (int i = 1; i < num.size(); i++) {
		if (num[i] > largest) {
			largest = num[i];
		}
	}

	if (largest > 'F') {
		return result;
	}

	if (largest >= 'A' && largest <= 'F') {
		result.is16 = true;
		return result;
	}

	if (largest > '7') {
		result.is16 = true;
		result.is10 = true;
		return result;
	}

	if (largest > '1') {
		result.is16 = true;
		result.is10 = true;
		result.is8 = true;
		return result;
	}

	
	result.is16 = true;
	result.is10 = true;
	result.is8 = true;
	result.is2 = true;
	return result;
	
}


/**
 * 
 * 
 * 进制判断
 * 
 * 测试链接：https://www.luogu.com.cn/problem/B3868
 * 
 * 考点：字符串操作；进制理解
 * 
 */
int main() {

	int n;
	std::cin >> n;

	std::string num;
	for (int i = 0; i < n; i++) {
		std::cin >> num;
		Result result = Check(num);
		std::cout << result.is2 << " " << result.is8 << " " << result.is10 << " " << result.is16 << std::endl;
	}


	return 0;
}   